<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@page import="org.apache.catalina.Session"%>
<%@ page import="java.sql.Date,java.sql.*"%>
<%@ page import="cn.ticket.db.DBConnect"%>
<%@ page import="cn.ticket.util.StringUtil"%>
<%@ page import="cn.ticket.Constant"%>

<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	String result = request.getParameter("result") ;
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>车次列表</title>
</head>
<body>
	<jsp:include page="../common/head.jsp"></jsp:include>
	<div class="content">
		<jsp:include page="../common/bar_left.jsp"></jsp:include>
		<div class="row">
		<label class="lable" style="margin-left:20px;"><b>车次管理</b>　　
				<%
				String user_type_temp=(String)session.getAttribute("login_user_type") ;
				int user_type= user_type_temp==null?-1:Integer.parseInt(user_type_temp) ;
				if(user_type==Constant.USER_PARTNER){
					%><a class="btn btn-primary" href="front/bus/busAdd.jsp">新增车次</a>　　<%=result==null?"":result %>
				<% 
					}
				%>
				</label>
			<table class="table table-hover">
				<tr>
					<td>序号</td>
					<td>车次</td>
					<td>始发站</td>
					<td>终点站</td>
					<td>价格</td>
					<td>开车时间</td>
					<td>总座位数</td>
					<td>剩余座位数</td>
					<td>操作</td>
				</tr>
				<%
					request.setCharacterEncoding("utf8");
					String id = StringUtil.createUUID();
					String type_ = (String) session.getAttribute("login_user_type");
					int type = null != type_ ? Integer.parseInt(type_) : -1;
					Connection con = new DBConnect().DBConnection();
					PreparedStatement pstmt=null ;
					try {
						String sql = "select * from bus where delSign!="+Constant.DEL_SIGN_DELETED;
						pstmt = con.prepareStatement(sql);
						ResultSet rs = pstmt.executeQuery();
						System.out.println(null==rs) ;
							while (rs.next()) {
						%>
						<tr>
							<td><%=rs.getRow()%></td>
							<td><%=rs.getString(2)%></td>
							<td><%=rs.getString(3)%></td>
							<td><%=rs.getString(4)%></td>
							<td><%=rs.getInt(5)%></td>
							<td><%=rs.getString(6)%></td>
							<td><%=rs.getInt(8)%></td>
							<td><%=rs.getInt(9)%></td>
							<td>
								<%
									if (type == Constant.USER_COMUSER) {
								%> 
								<a class="btn btn-primary"
										href="<%=basePath%>front/ticket/ticketAdd.jsp?id=<%=rs.getString(1)%>">预订</a>
								<%
									} else if (type == Constant.USER_PARTNER) {
								%> <a class="btn btn-primary"
											href="<%=basePath%>front/bus/busUpdate.jsp?id=<%=rs.getString(1)%>">修改</a>
									<a class="btn btn-primary busDel" id="<%=rs.getString(1)%>">删除</a>
								<%
									}
								%>
								</td>
					</tr>
					<%
						}
					} catch (Exception e) {
						e.printStackTrace();
						session.setAttribute("errorinfo", Constant.ERRORINFO_NETERROR) ;
						%>
							<jsp:forward page="../result.jsp"></jsp:forward>
						<%
					}finally{
						pstmt.close();
						con.close() ;
					}
				%>
				</tr>
			</table>
		</div>
		</div>
		<jsp:include page="../common/footer.jsp"></jsp:include>
		<script type="text/javascript">
			$('.busDel').click(function(){
				var truthBeTold = window.confirm("确定要删除此车次吗?删除后将无法恢复."); 
				if (truthBeTold) { 
					window.location.href="<%=basePath%>front/bus/busDel_handle.jsp?id="+$(this).attr('id') ;
				}
			})
		</script>
</body>
</html>